package com.solome.base;

/*********************************************************************
 * @author soells
 * @version 0.1
 */
public class GameStatus implements Status<Object> {

	/**
	 * 创建一个状态对象，只简单地携带标记位
	 * 
	 * @param success
	 *            成功标记
	 * @return 状态对象
	 */
	public static GameStatus getInstance(boolean success) {
		GameStatus status = new GameStatus();
		status.setSuccess(success);
		return status;
	}

	/**
	 * 创建一个状态对象，携带标记和信息
	 * 
	 * @param success
	 *            成功标记
	 * @param message
	 *            携带信息
	 * @return 状态对象
	 */
	public static GameStatus getInstance(boolean success, String message) {
		GameStatus status = new GameStatus();
		status.setSuccess(success);
		status.setMessage(message);
		return status;
	}

	/**
	 * 创建一个状态对象，携带标记和信息
	 * 
	 * @param success
	 *            成功标记
	 * @param message
	 *            携带信息
	 * @return 状态对象
	 */
	public static GameStatus getInstance(int statusCode, boolean success,
			String message) {
		GameStatus status = new GameStatus();
		status.setStatusCode(statusCode);
		status.setSuccess(success);
		status.setMessage(message);
		return status;
	}

	/** 绑定对象 */
	protected Object bindObject;
	/** 消息说明 */
	protected String message;
	/** 状态码 */
	protected int statusCode;
	/** 是否成功 */
	protected boolean success;

	// /** 携带的参数 */
	// protected List<TypePackage> packages = new
	// CopyOnWriteArrayList<TypePackage>();

	/**
	 * 
	 */
	public GameStatus() {
		super();
	}

	/**
	 * @param message
	 * @param statusCode
	 */
	public GameStatus(int statusCode, String message) {
		super();
		this.message = message;
		this.statusCode = statusCode;
	}

	/**
	 * @param message
	 * @param statusCode
	 * @param success
	 */
	public GameStatus(int statusCode, String message, boolean success) {
		super();
		this.message = message;
		this.statusCode = statusCode;
		this.success = success;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#clone()
	 */
	@Override
	public GameStatus clone() {
		GameStatus status = new GameStatus();
		status.setSuccess(isSuccess());
		status.setStatusCode(statusCode);
		status.setMessage(message);
		status.setBindingObject(bindObject);
		return status;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cn.core.Status#getBindingObject()
	 */
	@Override
	public Object getBindingObject() {
		return bindObject;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.solome.core.Status#getMessage()
	 */
	@Override
	public String getMessage() {
		return message;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.solome.core.Status#getStatusCode()
	 */
	@Override
	public int getStatusCode() {
		return statusCode;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.solome.core.Status#isSuccess()
	 */
	@Override
	public boolean isSuccess() {
		return success;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.solome.core.Status#setBindingObject(java.lang.Object)
	 */
	@Override
	public void setBindingObject(Object obj) {
		bindObject = obj;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.solome.core.Status#setMessage(java.lang.String)
	 */
	@Override
	public void setMessage(String message) {
		this.message = message;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cn.core.Status#setStatusCode(int)
	 */
	@Override
	public void setStatusCode(int code) {
		this.statusCode = code;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.solome.core.Status#setSuccess(boolean)
	 */
	@Override
	public void setSuccess(boolean value) {
		this.success = value;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		String msg = "[Status] Success=" + success + ", Message=" + message;
		if (statusCode > 0)
			msg += ", StatusCode=" + statusCode;
		if (bindObject != null)
			msg += ", Bind=" + bindObject;
		return msg;
	}
}
